<?php
/*
	订单管理
*/
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
    //验证是否为员工
$worker = pdo_get('jy_dish_staff',array('uniacid'=>$_SESSION['uniacid'],'mid'=>$_SESSION['uid']));
if($worker['id']){
	$group = pdo_get('jy_dish_staff_group',array('id'=>$worker['group_id']));	
	//string转数组	
	$ops=explode(";",$group['ops']);
	//是否有操作权限
	if(in_array('1',$group['ops'])){
		
	}
	else{
	//	exi('无操作权限','error');
	}
	$this->session('store_id',$worker['store_id']);
}
else{
	exi('非员工无法访问！','error');
}
$member=pdo_get('core_members',array('id'=>$_SESSION['uid'],'uniacid'=>$_SESSION['uniacid']),array('credit1','credit2','mobile','groupid','avatar','nickname'));
$worker['title']=$worker['title']?$worker['title']:$member['nickname'];
$worker['avatar']=$worker['avatar']?$worker['avatar']:$member['avatar'];
$return['worker']=$worker;
if($_RQ['op']=='main'){
	$daytime = mktime(0,0,0,date('m'),date('d'),date('Y'));
	//获得员工对应的门店id
	$store_id = $this->session('store_id');
	//对应门店的订单数据
	$orderlist = pdo_getall('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id'=>$store_id));
	$return['orderlist']=$orderlist;
	$return['storetitle']=pdo_getcolumn('jy_dish_store',array('uniacid'=>$_SESSION['uniacid'],'id'=>$store_id),'title');
	$return['all_num']=pdo_count('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id'=>$store_id),'id');
	$return['today_num']=pdo_count('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id'=>$store_id,'createtime >'=>$daytime),'id');
	$return['today_money']=pdo_getsum('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id'=>$store_id,'status >'=>0,'createtime >'=>$daytime),'price');
	$return['all_money']=pdo_getsum('jy_dish_order',array('uniacid'=>$_SESSION['uniacid'],'store_id'=>$store_id,'status >'=>0),'price');
	set_html('title','管理中心');
	exi($return);
}
if($_RQ['op']=='confirm'){
	//订单id
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
	$status=pdo_getcolumn('jy_dish_order',array('id'=>$id),'status');
	if($status == 0){
		$this->order_change(array('order_id'=>$id,'status'=>'1'));
	}
	else{
		exi('订单状态错误！','error');
	}
	
	exi('修改订单状态成功！');
}
if($_RQ['op']=='complete'){
	$id=intval($_RQ['id']);
	if(!$id){
		exi('请先选择订单！','error');
	}
	$status=pdo_getcolumn('jy_dish_order',array('id'=>$id),'status');
	if($status==1){
		$this->order_change(array('order_id'=>$id,'status'=>'2'));
	}
	else{
		exi('订单状态错误！','error');
	}
	exi('修改订单状态成功！');
}
